//
//  TenderListController.swift
//  SlaughterClient
//
//  Created by 邱仙凯 on 2019/12/30.
//  Copyright © 2019 zwb. All rights reserved.
//

import UIKit
import SVProgressHUD
enum TBandJPType { // 投标，销售招标
    case TB,JP
}
let categoryDicDesc = ["3":"原料","4":"物流","5":"药品"]
let leixingArr = ["全部","原料","物流","药品"]
let leixingDic = ["全部":"3,4,5","原料":"3","物流":"4","药品":"5"]

let zhuangtaiArr_zb = ["全部","未开始","已开标","进行中","已结束","已流标"]
let zhuangtaiDic_zb = ["全部":"","未开始":"0","已开标":"1","进行中":"2","已结束":"3","已流标":"4"]

let zhuangtaiArr_jp = ["全部","未开始","已开拍","进行中","已结束","已流拍"]
let zhuangtaiDic_jp = ["全部":"","未开始":"0","已开拍":"1","进行中":"2","已结束":"3","已流拍":"4"]


public enum ZTBInnerType { // 区分各个进入的地方
   
        case zbListKHW,  // 招标列表
             jpListKHW, // 销售招标列表
             tbRecordKHW,  // 投标记录
             chujiaRecordKHW,  // 出价记录
             zbMyPublishKHW, // 我的发布
             tbMytbKHW, // 我的投标
             jpMyjpKHW, // 我的销售招标
             tbMyMarkKHW, // 我的收藏投标
             jpMyMarkKHW, // 我的收藏销售招标
             recommendKHW, // 为你推荐
             cjAnnouncementKHW, // 成交公告
             zbAnnouncementKHW, // 中标公告
    
              chujiaRecordJP, // 竞拍进度 里的  出价记录
             zbInfo_ylOA,//  oaapp   招标(原料)
             zbInfo_wlOA,//  oaapp      招标(物流)
             zbInfo_drugOA,//   oaapp   招标(药品)
             jpInfo_oaOA, //    oaapp       竞拍(猪业)
             zbInfo_followTagOA, //    oaapp  招标管理  招标进度列表
             jpInfo_followTagOA, //    oaapp    竞拍进度列表
             tbRecord_followTagOA //   oaapp     投标情况
     
    
}


struct tenderfilterParam {
    var startDate = ""
    var endDate = ""
    var minMoney = ""
    var maxMoney = ""
    var zStatus = ""
    var zSort = "1"
    var zProvince = ""
    var zCity = ""
    var searchTitle = ""
    var outDate = ""
    var categoryNm = "全部"   // 类型
    var z_contract_state = ""
}
class TenderListController: TenderBaseTableController,UISearchBarDelegate {
    
    var page = 1
    
    var titleStr:ZTBInnerType = ZTBInnerType.zbListKHW
    var dataArray = [ZtbContentModel]()
    var z_zb_id = "" // 投标记录使用
    
    var listType = TBandJPType.TB
    var btnflag = "1"
    
    
    var followTag = ""
   
    private var searchBar:UISearchBar?
    
    
    init(listType:TBandJPType = .TB,titleStr:ZTBInnerType,z_zb_id:String = "",searchTitle:String = "",followTag:String = "0") {
        super.init(nibName: nil, bundle: nil)
        self.titleStr = titleStr
        self.listType = listType
        self.followTag = followTag
        self.z_zb_id = z_zb_id
        self.helper.filterPa!.searchTitle = searchTitle
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setSearchBar()
        helper.callTableRefreshClosure = {
            self.tableView.mj_header?.beginRefreshing()
            
        }
 
        
        tableView.estimatedRowHeight = 50
        tableView.rowHeight = UITableView.automaticDimension
        
        tableView.mj_header = KSRefreshHeader { [unowned self] in
            self.page = 1
            self.network()
        }
        tableView.mj_footer = KSRefreshFooter { [unowned self] in
            self.page += 1
            self.network()
        }
        tableView.mj_header?.beginRefreshing()
        
        tableView.register(TenderFirstCell.self, forCellReuseIdentifier: TenderFirstCell.identifier)
        tableView.register(TenderWuliuCell.self, forCellReuseIdentifier: TenderWuliuCell.identifier)
        tableView.register(MyTenderJPCell.self, forCellReuseIdentifier: MyTenderJPCell.identifier)

        tableView.register(TenderFollowTagCell.self, forCellReuseIdentifier: TenderFollowTagCell.identifier)
        
        
        if self.titleStr == .tbRecordKHW || self.titleStr == .chujiaRecordKHW || self.titleStr == .chujiaRecordJP  || self.titleStr == .tbRecord_followTagOA {
            
        } else {
            
            let menu = XYXFilterMenu.init(frame: CGRect(x: 0, y: 0, width: KSGlobal.screenW, height: 40))
            menu.finalChooseClo = { s0,s1_0,s1_1,s2,min,max in
                /// 顶部前三个筛选返回处理
                
                let orgin_sort = self.helper.filterPa!.zSort
                let orgin_zprovince = self.helper.filterPa!.zProvince
                let orgin_zcity = self.helper.filterPa!.zCity
                let orgin_startDate = self.helper.filterPa!.startDate
                let orgin_endDate = self.helper.filterPa!.endDate
                let orgin_minValue = self.helper.filterPa!.minMoney
                let orgin_outDate = self.helper.filterPa!.outDate
                let orgin_maxValue = self.helper.filterPa!.maxMoney
                let orgin_status = self.helper.filterPa!.zStatus
                let orgin_category = self.helper.filterPa!.categoryNm
                if s0.isSome {
                    if self.listType == .TB {
                        self.helper.filterPa!.zStatus = zhuangtaiDic_zb[zhuangtaiArr_zb[s0!]]!
                    } else {
                        self.helper.filterPa!.zStatus = zhuangtaiDic_jp[zhuangtaiArr_jp[s0!]]!
                    }
                    
                    
                }
                if s1_0.isSome && s1_1.isSome {
                    // 区域返回 索引
                    
                    let  provNm = provinceArr[s1_0!]
                    let cityArr = cityDic[provNm]!
                    
                    if cityArr.count > 1 {
                        if s1_1! == 0 {
                            self.helper.filterPa!.zCity = ""
                            self.helper.filterPa!.zProvince = provNm
                        } else {
                            self.helper.filterPa!.zCity =  cityArr[s1_1! - 1]
                            self.helper.filterPa!.zProvince = ""
                        }
                    } else {
                        self.helper.filterPa!.zCity =  cityArr.first!
                        self.helper.filterPa!.zProvince = ""
                    }
                    
                    
                    
                }
                if s2.isSome {
                    
                    self.helper.configParam(s2:s2!)
                }
                
                
                self.helper.filterPa!.minMoney = min
                self.helper.filterPa!.maxMoney = max
                
                
                if orgin_sort == self.helper.filterPa!.zSort &&
                    orgin_zprovince == self.helper.filterPa!.zProvince &&
                    orgin_zcity == self.helper.filterPa!.zCity &&
                    orgin_startDate == self.helper.filterPa!.startDate &&
                    orgin_endDate == self.helper.filterPa!.endDate &&
                    orgin_minValue == self.helper.filterPa!.minMoney &&
                    orgin_maxValue == self.helper.filterPa!.maxMoney &&
                    orgin_outDate == self.helper.filterPa!.outDate &&
                    orgin_status == self.helper.filterPa!.zStatus &&
                    orgin_category == self.helper.filterPa!.categoryNm   {
                    
                } else {
                    self.tableView.mj_header?.beginRefreshing()
                }
                
                
            }
            menu.dataSource = self
            menu.delegate = self
            tableView.tableHeaderView = menu
            
            
        }
        
        
        
        tableView.tableFooterView = UIView()
        
        
    }
    @objc func doneClickss() {
        self.searchBar!.resignFirstResponder()
    }
    
    func setSearchBar () {
        searchBar = TenderSearchBar(frame:CGRect(x:0,y:0,width:KSGlobal.screenW * 0.65,height:40))
        let toolbar = UIToolbar()
        toolbar.barStyle = UIBarStyle.default
        toolbar.sizeToFit()
        let buttonflexible = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
        let buttonDone = UIBarButtonItem(title: "完成", style: UIBarButtonItem.Style.done, target: self, action: #selector(doneClickss))
        buttonDone.tintColor = UIColor.black
        toolbar.setItems([buttonflexible, buttonDone], animated: true)
        
        searchBar!.inputAccessoryView = toolbar
        
        searchBar!.layer.cornerRadius = 15
        searchBar!.layer.masksToBounds = true
        
        // 导航栏背景不同，需要改变搜索框背景色
        var searBColor:UIColor!
        if  titleStr == .zbInfo_ylOA ||
                titleStr == .zbInfo_wlOA ||
                titleStr == .zbInfo_drugOA ||
                titleStr == .jpInfo_oaOA ||
                titleStr == .zbInfo_followTagOA ||
                titleStr == .jpInfo_followTagOA ||
                 titleStr == .tbRecord_followTagOA ||
                titleStr == .chujiaRecordJP {
        searBColor = UIColor(kshex: "#f7f7f7")
      } else {
        searBColor = .white
      }

        
        if #available(iOS 13.0, *) {
            searchBar!.searchTextField.backgroundColor = searBColor
            searchBar!.searchTextField.layer.cornerRadius = 18
            searchBar!.searchTextField.layer.masksToBounds = true
        } else {
            // Fallback on earlier versions
            let searchField = searchBar!.value(forKey: "searchField") as! UITextField
            searchField.backgroundColor = searBColor
            searchField.layer.cornerRadius = 18
            searchField.layer.masksToBounds = true
            
        }
        
        
        searchBar!.text = self.helper.filterPa!.searchTitle
        searchBar!.placeholder = "搜索"
        searchBar!.delegate = self
        let searchView = UIView(frame:CGRect(x:0,y:0,width:KSGlobal.screenW * 0.65 ,height:40))
        searchView.addSubview(searchBar!)
        self.navigationItem.titleView = searchView
        if self.titleStr == .zbMyPublishKHW {
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "发布", style: .done, target: self, action: #selector(publishAction))
        } else if self.titleStr == .zbListKHW || self.titleStr == .jpListKHW  {
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "地图", style: .done, target: self, action: #selector(mapAction))
        } else {
            
        }
    }
    @objc func publishAction() {
        self.helper.publishTender(controller:self)
    }
    @objc func mapAction() {
        
    }
    
    func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        searchBar.resignFirstResponder()
        self.helper.filterPa!.searchTitle = searchBar.text.unwrap
        self.tableView.mj_header?.beginRefreshing()
    }
    
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.dataArray.count
    }
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if self.titleStr == .tbRecord_followTagOA {
            guard let cell = tableView.dequeueReusableCell(withIdentifier: TenderFollowTagCell.identifier, for: indexPath) as? TenderFollowTagCell else {
                fatalError("cell error")
            }
            cell.one = self.dataArray[indexPath.row]
            
            return cell
        } else {
            let one = self.dataArray[indexPath.row]
            if self.listType == .TB && one.zDtradeType == "4" { //   招标物流
                guard let cell = tableView.dequeueReusableCell(withIdentifier: TenderWuliuCell.identifier, for: indexPath) as? TenderWuliuCell else {
                    fatalError("cell error")
                }
             
                cell.makeConstrainsts()
             
 
                 one.innerType = titleStr
                cell.btn2Closure = { [one, unowned self] btn,btnTitle in
                    
                    if btnTitle == "" {
                        
                        
                        if self.btnflag == "1" {
                            
                            self.btnflag = "0"
                            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
                                self.btnflag = "1"
                            }
                            
                            
                            let phone = "tel://" + one.zTel.unwrap
                            if UIApplication.shared.canOpenURL(URL(string: phone)!) {
                                
                                UIApplication.shared.open(URL(string: phone)!, options: [:], completionHandler: { result in
                                })
                                
                            } else {
                                KSToast("电话错误")
                            }
                        }
                        
                        
                    } else  if btnTitle == "编辑" {
                        
                        self.helper.go2TenderAddController(controller:self,idkey:one.idKey.unwrap,excuteType:.fix) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else  if btnTitle == "查看投标" {
                        
                        self.helper.go2TenderTbController(listType: self.listType, controller:self,z_tb_id:one.zTbId.unwrap,excuteType:.fix,model:one) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else  if btnTitle == "查看销售招标" {
                        
                        self.helper.go2TenderTbController(listType: self.listType, controller:self,z_bid_id:one.idKey.unwrap,excuteType:.fix) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else if btnTitle == "投标记录" { // 分两种 followTag 0 和  1
                        if one.zDtradeType == "5" && listType == .TB { // 药品投标
                            self.helper.go2TenderRecord(controller:self,id:one.idKey.unwrap)
                         } else {
                            let  vc = OldTBJL_WLVC(titleStr: .tbRecordKHW, z_zb_id: one.idKey.unwrap,followTag: self.followTag)
                            self.navigationController?.pushViewController(vc, animated: true)
                        }
                        
                       
                        
                        
                        
                    } else if btnTitle == "投标情况" { // 分两种 followTag 0 和  1
                        
                        let  vc = TenderListController(titleStr: .tbRecord_followTagOA, z_zb_id: one.idKey.unwrap,followTag: self.followTag)
                        self.navigationController?.pushViewController(vc, animated: true)
                        
                        
                        
                    } else if btnTitle == "出价记录" {
                        if self.titleStr == .jpInfo_followTagOA {
                            let  vc = TenderListController(titleStr: .chujiaRecordJP, z_zb_id: one.idKey.unwrap)
                           self.navigationController?.pushViewController(vc, animated: true)
                        } else {
                            let  vc = TenderListController(titleStr: .chujiaRecordKHW, z_zb_id: one.idKey.unwrap)
                           self.navigationController?.pushViewController(vc, animated: true)
                        }
                         
     
                    }  else {
                        self.helper.unReferTb(controller:self,idkey:one.idKey.unwrap)
                        
                        
                    }
                    
                    
                }
                cell.one = one
                
                
                return cell
            } else if self.titleStr == .jpMyjpKHW {
                guard let cell = tableView.dequeueReusableCell(withIdentifier: MyTenderJPCell.identifier, for: indexPath) as? MyTenderJPCell else {
                    fatalError("cell error")
                }
             
                cell.makeConstrainsts()
              
                one.innerType = titleStr
                cell.operateBtn.clickAction = { [one] btn,btnTitle in
                         
                    if btnTitle == "查看竞拍" {
                        self.helper.go2TenderTbController(listType: self.listType, controller:self,z_bid_id:one.idKey.unwrap,excuteType:.fix) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                    } else {
                        self.helper.go2CarInfo(idkey: one.idKey.unwrap, controller: self)
                    }
                        
                        
                    }
        
                cell.one = one
                
                
                return cell
            } else {
                guard let cell = tableView.dequeueReusableCell(withIdentifier: TenderFirstCell.identifier, for: indexPath) as? TenderFirstCell else {
                    fatalError("cell error")
                }
             
                cell.makeConstrainsts(self.listType)
             
                
                
                
                one.innerType = titleStr
                cell.btn2Closure = { [one, unowned self] btn,btnTitle in
                    
                    if btnTitle == "" {
                        
                        
                        if self.btnflag == "1" {
                            
                            self.btnflag = "0"
                            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
                                self.btnflag = "1"
                            }
                            
                            
                            let phone = "tel://" + one.zTel.unwrap
                            if UIApplication.shared.canOpenURL(URL(string: phone)!) {
                                
                                UIApplication.shared.open(URL(string: phone)!, options: [:], completionHandler: { result in
                                })
                                
                            } else {
                                KSToast("电话错误")
                            }
                        }
                        
                        
                    } else  if btnTitle == "编辑" {
                        
                        self.helper.go2TenderAddController(controller:self,idkey:one.idKey.unwrap,excuteType:.fix) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else  if btnTitle == "查看投标" {
                        
                        self.helper.go2TenderTbController(listType: self.listType, controller:self,z_tb_id:one.zTbId.unwrap,excuteType:.fix,model:one) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else  if btnTitle == "查看销售招标" {
                        
                        self.helper.go2TenderTbController(listType: self.listType, controller:self,z_bid_id:one.idKey.unwrap,excuteType:.fix) {
                            self.tableView.mj_header?.beginRefreshing()
                        }
                        
                        
                    } else if btnTitle == "投标记录" { // 分两种 followTag 0 和  1
                        if one.zDtradeType == "5" && listType == .TB { // 药品投标
                            self.helper.go2TenderRecord(controller:self,id:one.idKey.unwrap)
                         } else {
                            let  vc = TenderListController(titleStr: .tbRecordKHW, z_zb_id: one.idKey.unwrap,followTag: self.followTag)
                            self.navigationController?.pushViewController(vc, animated: true)
                        }
                        
                        
                        
                    } else if btnTitle == "投标情况" { // 分两种 followTag 0 和  1
                        
                        let  vc = TenderListController(titleStr: .tbRecord_followTagOA, z_zb_id: one.idKey.unwrap,followTag: self.followTag)
                        self.navigationController?.pushViewController(vc, animated: true)
                        
                        
                        
                    } else if btnTitle == "出价记录" {
                        if self.titleStr == .jpInfo_followTagOA {
                            let  vc = TenderListController(titleStr: .chujiaRecordJP, z_zb_id: one.idKey.unwrap)
                           self.navigationController?.pushViewController(vc, animated: true)
                        } else {
                            let  vc = TenderListController(titleStr: .chujiaRecordKHW, z_zb_id: one.idKey.unwrap)
                           self.navigationController?.pushViewController(vc, animated: true)
                        }
                         
     
                    }  else {
                        self.helper.unReferTb(controller:self,idkey:one.idKey.unwrap)
                        
                        
                    }
                    
                    
                }
                cell.one = one
                
                
                return cell
            }
            
          
        }
        
        
    }
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        if self.titleStr == .tbRecordKHW || self.titleStr == .chujiaRecordKHW {
            
            self.helper.go2TenderTbDetailController(listType: .TB, controller:self,idkey:self.dataArray[indexPath.row].idKey.unwrap,innerType:self.titleStr)
            
        } else if self.titleStr == .chujiaRecordJP {
            
        } else {
            var idkey:String = ""
            if self.titleStr == .tbMytbKHW || self.titleStr == .jpMyjpKHW {
                idkey = self.dataArray[indexPath.row].zZbId.unwrap
            } else if self.titleStr == .tbMyMarkKHW || self.titleStr == .jpMyMarkKHW {
                idkey = self.dataArray[indexPath.row].zRecordId.unwrap
            } else { // 我的招标  招投标
                idkey = self.dataArray[indexPath.row].idKey.unwrap
            }
            
            go2TenderInfoController(listType: self.listType, fromVC:self,idkey:idkey,voccd: "",innerType:self.titleStr)
            
        }
        
        
    }
    func network () {
        let api = self.helper.titleStrToAPI(listType:self.listType,titleStr: titleStr, startDate: self.helper.filterPa!.startDate, endDate: self.helper.filterPa!.endDate, maxValue: self.helper.filterPa!.maxMoney, minValue: self.helper.filterPa!.minMoney,zprovince: self.helper.filterPa!.zProvince, zcity: self.helper.filterPa!.zCity, searchTitle: self.helper.filterPa!.searchTitle, page: self.page, z_zb_id: z_zb_id, sortType: self.helper.filterPa!.zSort,z_status: self.helper.filterPa!.zStatus,outDate:self.helper.filterPa!.outDate,category: self.helper.filterPa!.categoryNm,followTag: self.followTag)
        
        
        KSNetwork.shared.doRequest(api,showHud: false) { [weak self] (data:BaseResult<ZtbContentModel>) in
            guard let `self` = self else { return }
            if data.flag == TRUE {
                if let infos = data.infoArrCombine {
                    if self.page == 1 {
                        self.dataArray.removeAll()
                    }
                    self.dataArray += infos
                    self.tableView.reloadData()
                    self.tableView.mj_header?.endRefreshing()
                    if infos.count < 10 {
                        self.tableView.mj_footer?.endRefreshingWithNoMoreData()
                    } else {
                        self.tableView.mj_footer?.endRefreshing()
                    }
         
                }
            } else {
                KSToast(data.errorCombine.unwrap)
            }
        }
    }
    
    
    deinit {
        print("tenderfirst 销毁")
    }
}


extension TenderListController:XYXFilterMenuDataSource {
    // 头部显示要改变的时候回调此方法
    func menu(_ menu: XYXFilterMenu, shouldChange title: String, for indexPath: XYXFilterIndexPath) -> String? {
        
        let titlesStr = self.listType == .TB ? self.helper.titles_zb[indexPath.column!] : self.helper.titles_jp[indexPath.column!]
        var theTitle = title
        if theTitle == "全部." {
            theTitle = provinceArr[indexPath.row!]
        }
        if theTitle == "全部" {
            theTitle = titlesStr
        }
        return theTitle
    }
    // 每个列展示的数组
    func menu(_ menu: XYXFilterMenu, numberOfRowsAt indexPath: XYXFilterIndexPath) -> Int {
        guard indexPath.column != nil else {
            return 0
        }
        switch indexPath.column! {
        case 0:
            return self.listType == .TB ? zhuangtaiArr_zb.count : zhuangtaiArr_jp.count
        case 1:
            return provinceArr.count
        case 2:
            if self.listType == .TB {
                return self.helper.source_tb_status.count
                
            } else {
                return self.helper.source_jp_status.count
            }
            
        case 3:
            return 1
        default:
            return 0
        }
    }
    
    func menu(_ menu: XYXFilterMenu, numberOfItemsAt indexPath: XYXFilterIndexPath) -> Int {
        guard indexPath.column != nil && indexPath.row != nil else {
            return 0
        }
        switch indexPath.column! {
        case 1:
            return cityDic[provinceArr[indexPath.row!]]!.count
        case 3:
            return 1
        default:
            return 0
        }
    }
    // 各个过滤项的 标题数组
    func menu(_ menu: XYXFilterMenu, titleOfRowAt indexPath: XYXFilterIndexPath) -> String {
        let defaultString = ""
        guard indexPath.column != nil && indexPath.row != nil else {
            return defaultString
        }
        switch indexPath.column! {
        case 0: // 状态（招标的时候）
            return self.listType == .TB ? zhuangtaiArr_zb[indexPath.row!] : zhuangtaiArr_jp[indexPath.row!]
        case 1: // 区域
            return provinceArr[indexPath.row!]
            
        case 2: // 时间
            if self.listType == .TB {
                return self.helper.source_tb_status[indexPath.row!]
            } else {
                return self.helper.source_jp_status[indexPath.row!]
            }
            
        default:
            return defaultString
        }
    }
    
    func menu(_ menu: XYXFilterMenu, titleOfItemAt indexPath: XYXFilterIndexPath) -> String {
        let defaultString = ""
        guard indexPath.column != nil && indexPath.row != nil && indexPath.item != nil else {
            return defaultString
        }
        if indexPath.column == 1 {
            var cityArr = cityDic[provinceArr[indexPath.row!]]!
            if cityArr.count > 1 {
                cityArr.insert("全部.", at: 0)
            } else {
                
            }
            return cityArr[indexPath.item!]
        }
        return defaultString
    }
    // 大菜单数量
    func numberOfColumns(menu: XYXFilterMenu) -> Int {
        return self.listType == .TB ? self.helper.titles_zb.count : self.helper.titles_jp.count
    }
    // 大标题数据
    func menu(_ menu: XYXFilterMenu, titleOfColumnAt index: Int) -> String {
        return self.listType == .TB ? self.helper.titles_zb[index] : self.helper.titles_jp[index]
    }
    // 菜单的样式，单列表 多列表   collectionview等
    func menu(_ menu: XYXFilterMenu, typeOfColumn: Int) -> XYXFilterView.ColumnType.RawValue {
        switch typeOfColumn {
        case 1:
            return XYXFilterView.ColumnType.TableViewTwo.rawValue
        case 0,2:
            return XYXFilterView.ColumnType.TableViewOne.rawValue
        default:
            return XYXFilterView.ColumnType.collectionViewType.rawValue
        }
    }
    
    func menu(_ menu: XYXFilterMenu, widthOf tableView: UITableView, at column: Int) -> CGFloat {
        if column == 1 {
            if tableView.tag == XYXFilterView.firstTabViewTag{
                return XYX_SCREEN_WIDTH * 0.35
            }else if tableView.tag == XYXFilterView.secondTabViewTag{
                return XYX_SCREEN_WIDTH * 0.65
            }
        }
        return XYX_SCREEN_WIDTH/2
    }
    
    // 菜单向下展开的高度
    func menu(_ menu: XYXFilterMenu, filterContentHeightAt column: Int) -> CGFloat {
        if column == 3 {
            return 200.0
        } else {
            return 300.0
        }
        
    }
    
}

extension TenderListController:XYXFilterMenuDelegate {
    func menu(_ menu:XYXFilterMenu, tapIndex: Int) {
        print(tapIndex)
    }
    func menu(_ menu: XYXFilterMenu, tapIndexShowEnable: Int) -> Bool {
        print(tapIndexShowEnable)
        if tapIndexShowEnable == 3 {
            self.helper.listFilterAction(listType: self.listType)
            return false
        } else {
            return true
        }
    }
}

